package com.zzy.controller;


import com.zzy.model.AjaxMsg;
import com.zzy.model.Catalog;
import com.zzy.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping(value = "/cata")
public class CatalogContoleer {

    @Autowired
    private CatalogService catalogService;


    @RequestMapping({"/list"})
    public String list( HttpServletRequest request) {
        List<Catalog> list  =  catalogService.getRootList();
        request.setAttribute("list",list);
        return "file_list.jsp";
    }

    @RequestMapping(value="/root")
    public void grid(Catalog model, HttpServletRequest request, HttpServletResponse response){

    }

    @RequestMapping(value="/next")
    public void next(Catalog model, HttpServletRequest request, HttpServletResponse response){
        List<Catalog> list  =  catalogService.getByParentid("");
    }

    @ResponseBody
    @RequestMapping({"/delete"})
    public AjaxMsg delete(String id) {
        return AjaxMsg.returnAjaxMsg();
    }


    @RequestMapping({"/jump"})
    public String jump( HttpServletRequest request) {
        String id = request.getParameter("id");
        if(StringUtils.hasText(id)){
            Catalog  model  =  catalogService.get(id);
            request.setAttribute("model",model);
        }
        return "page/catalog/detail.jsp";
    }


    @ResponseBody
    @RequestMapping({"/save"})
    public AjaxMsg save(Catalog catalog) {
        catalogService.save(catalog);
        return AjaxMsg.returnAjaxMsg();
    }


    @ResponseBody
    @RequestMapping({"/update"})
    public AjaxMsg update(Catalog catalog) {
        return AjaxMsg.returnAjaxMsg(catalogService.update(catalog));
    }


    @ResponseBody
    @RequestMapping({"/get"})
    public AjaxMsg get(String id) {
        return AjaxMsg.returnAjaxMsg();
    }


}
